package com.blogspot.javagamexyz.gamexyz.ui;

import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.blogspot.javagamexyz.gamexyz.components.Stats;
import com.blogspot.javagamexyz.gamexyz.custom.Globals;

//TODO set a standard size and move to the bottom of the screen (will be underneath inventory and equip menu)
public class StatsHUD {
	
	Stage stage;
	Skin skin;
	public HUD hud;
	
	public Label nameVal;
	public Label agilityVal, smartsVal, spiritVal, strengthVal, vigorVal;
	public Label parryVal, toughnessVal, charismaVal, paceVal;
	public Label woundsVal, fatigueVal;
	public Label fightingVal, shootingVal;
	
	public void drawDebug(){
		Table.drawDebug(stage);
	}
	
	public StatsHUD(Stage stage){
		this.stage = stage;		   	
    	
		FileHandle skinFile = new FileHandle("resources/uiskin/uiskin.json");
		skin = new Skin(skinFile);		
		
		hud = new HUD(skin, 250, stage.getHeight());	//TODO make this work with smaller screens and stuff

		createLabels();	
		//formatTable();	//Not used anymore
		populateTable();				

		hud.addToStage(stage, 0, stage.getHeight());
	}
	/*	//We don't need this anymore
	public StatsHUD(Table table){
		//this.stage = stage;		
		masterTable = table;
    	
		FileHandle skinFile = new FileHandle("resources/uiskin/uiskin.json");
		skin = new Skin(skinFile);		
		
		hud = new HUD(skin, 250, 720);	//TODO make this work with smaller screens and stuff

		createLabels();	
		formatTable();	
		populateTable();				

		//hud.addToStage(stage, 0, stage.getHeight());
		//masterTable.add(statsTable);	//TODO NONONONO
		//hud.addToTable(masterTable);	//eh no then we can't properly set things up
		masterTable.add(hud.getHudTable()).width(40);//obviously need to play around with this
	}*/
	
	public void createLabels(){
		//Initialize variable labels
    	nameVal = new Label("Endless Nameless One", skin);
    	agilityVal = new Label("0", skin);
    	smartsVal = new Label("0", skin);
    	spiritVal = new Label("0", skin);
    	strengthVal = new Label("0", skin);
    	vigorVal = new Label("0", skin);   
    	woundsVal = new Label("0", skin);  
    	fatigueVal = new Label("0", skin);  
    	parryVal = new Label("0", skin);  
    	toughnessVal = new Label("0", skin); 
    	fightingVal = new Label("0", skin);  
    	shootingVal = new Label("0", skin); 
	}
	
	public void populateTable(){
		//Build Table    	
    	hud.addLabel("Name:");
    	hud.addLabel(nameVal);
    	hud.addRow();    	
    	
    	hud.addLabel("Agility:");
    	hud.addLabel(agilityVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Smarts:");
    	hud.addLabel(smartsVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Spirit:");
    	hud.addLabel(spiritVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Strength:");
    	hud.addLabel(strengthVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Vigor:");
    	hud.addLabel(vigorVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Parry:");
    	hud.addLabel(parryVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Tough:");
    	hud.addLabel(toughnessVal);
    	hud.addRow(); 
    	
    	hud.addLabel("------------");
    	hud.addLabel("------------");
    	hud.addRow();
    	
    	hud.addLabel("Wounds:");
    	hud.addLabel(woundsVal);
    	hud.addRow(); 
    	
    	hud.addLabel("Fatigue:");
    	hud.addLabel(fatigueVal);
    	hud.addRow();   
    	
    	hud.addLabel("------------");
    	hud.addLabel("------------");
    	hud.addRow();
    	
    	hud.addLabel("Fighting:");
    	hud.addLabel(fightingVal);
    	hud.addRow();
    	
    	hud.addLabel("Sooting:");
    	hud.addLabel(shootingVal);
    	hud.addRow();
	}
	
	/*public void formatTable(){	//uhh... hmmm. why is this being handle here? I don't like this
		//basically what is happening here is that we have made a new table with a table inside... or something, godfuckingdamnit yarg
		//actually I don't think this even does anything, which is why it was filling up the whole background before, because it is not the contrained table setup in HUD
		//statsTable = new Table(skin).debug();
		//statsTable.setFillParent(true);	//table shows up at first, but disappears when context menu comes up. also fills up the whole screen with the background. not used by FramedMenu
		//statsTable.setBackground(skin.getTiledDrawable("menuTexture"));	//fills up entire screen
    	//statsTable.left().top(); 	
		//statsTable.setWidth(5);	//doesn't do shit
    	//statsTable.
    	//TODO before upgrading everything play with this stuff

	}*/
	
	public void process(Stats stats){
		updateStatsHud(stats);
		hud.setVisible(true);	//I don't think we really need this, but whatever.
	}
	
	public void updateStatsHud(Stats stats){
		nameVal.setText(stats.name);
		agilityVal.setText(stats.getAgility() + "");
		smartsVal.setText(stats.getSmarts() + "");
		spiritVal.setText(stats.getSpirit() + "");
		strengthVal.setText(stats.getStrength() + "");
		vigorVal.setText(stats.getVigor() + "");	
		woundsVal.setText(stats.wounds + "");	
		fatigueVal.setText(stats.fatigue + "");		
		parryVal.setText(stats.getStatTotal(Globals.PARRY) + "");
		toughnessVal.setText(stats.getStatTotal(Globals.TOUGHNESS) + "");
		fightingVal.setText(stats.getStatTotal(Globals.FIGHTING) + "");
		shootingVal.setText(stats.getStatTotal(Globals.SHOOTING) + "");
	}
	
	
	public Table getHudTable(){
		return hud.getHudTable();	//for some reason this feels stupid... but oh well.
	}

}
